"""
演示读取文件，然后进行排序的操作
"""
def read_fail():
    result = []
    with open("students_grade","r",encoding="UTF-8") as f:
        for line in f:
            line = line.strip()
            result.append(line.split(","))
    return result

def sort_date(dates):
    return sorted(dates,key = lambda x:int(x[2]),reverse=True)

def out_date(dates):
    with open("students_grade_output","w",encoding="UTF-8") as f:
        for date in dates:
            f.write(",".join(date)+"\n")
# 读取文件
dates = read_fail()
print(dates)

# 进行排序
dates = sort_date(dates)
# 写出文件
out_date(dates)